/** # feeds信息流 模块 */
import { contacts, createContact } from '@/api/contact';
import * as types from '../mutation-types';

// initial state
const state = {
  contacts: null, // []
  contact: null,
  createdContact: {},
};

// getters
const getters = {
  getContacts: state => state.contacts,
  getContact: state => state.contact,
  getCreatedContact: state => state.createdContact,
};
// actions
const actions = {
  fetchContacts(context, params) {
    contacts(params)
    .then(data => context.commit(types.FETCH_CONTACTS, data.data));
  },
  createContacts(context, params) {
    createContact(params)
    .then((data) => {
      context.commit(types.CREATE_CONTACTS, data);
    });
  },
};

// mutations
const mutations = {
  [types.FETCH_CONTACTS](state, data) {
    // eslint-disable-next-line
    state.contacts = data;
  },
  [types.CREATE_CONTACTS](state, data) {
    // eslint-disable-next-line
    state.createdContact = data;
  },
};


export default {
  state,
  getters,
  actions,
  mutations,
};
